<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page import="java.sql.ResultSet"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"
	import="
org.codehaus.jackson.map.ObjectMapper,java.sql.PreparedStatement,org.springframework.context.support.AbstractApplicationContext,org.springframework.context.support.ClassPathXmlApplicationContext,com.alibaba.druid.pool.DruidDataSource"%>
<%
	AbstractApplicationContext ac = new ClassPathXmlApplicationContext(
			"spring-config.xml");
	DruidDataSource dataSource = (DruidDataSource) ac
			.getBean("dataSource");
	ObjectMapper jsonTool = (ObjectMapper) ac.getBean("jsonTool");
	//获取certSn参数
	String certSn = request.getParameter("certSn");
	//System.out.print(certSn);
	String sql = "SELECT USER_ID FROM ica_ca_cert WHERE CERT_SERIALNUMBER=?";
	out.print(querySql(sql, dataSource, jsonTool,certSn));
	//response.getWriter().write(querySql(sql, dataSource, jsonTool));
%>
<%!private void executeSql(String sql, DruidDataSource dataSource) {
		java.sql.Connection conn = null;
		PreparedStatement stmt = null;
		try {
			conn = dataSource.getConnection();
			stmt = conn.prepareStatement(sql);
			stmt.execute();

		} catch (java.sql.SQLException e) {
			e.printStackTrace();
		} finally {
			try {
				if (null != stmt) {
					stmt.close();
				}
				if (null != conn) {
					conn.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}%>
<%!private String querySql(String sql, DruidDataSource dataSource,
			ObjectMapper jsonTool,String certSn) {
		java.sql.Connection conn = null;
		PreparedStatement stmt = null;
		ResultSet result = null;
		String jsonStr = "";
		java.util.Map<String, Object> jsonMap = new java.util.HashMap<String, Object>();
		List<String> jsonList = new ArrayList<String>();
		try {
			conn = dataSource.getConnection();
			stmt = conn.prepareStatement(sql);
			stmt.setString(1, certSn);
			result = stmt.executeQuery();
			while (result.next()) {
				jsonMap.put("USER_ID", result.getString("USER_ID"));
				//jsonMap.put("model", result.getString("model"));
				jsonList.add(jsonTool.writeValueAsString(jsonMap));
			}

		} catch (java.sql.SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (null != result) {
					result.close();
				}
				if (null != stmt) {
					stmt.close();
				}
				if (null != conn) {
					conn.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		try {
			jsonStr = jsonTool.writeValueAsString(jsonList);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonStr;
	}%>

<%
	ac.close();
%>